package com.supreme.businessserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.supreme.businessserver.mapper.mybatis.MBProductMapper;
import com.supreme.commonentity.mysql.primary.BizProduct;
import com.supreme.commonboot.utils.AjaxResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "product")
public class ProductController {

    private final MBProductMapper mbProductMapper;

    @Autowired
    public ProductController(MBProductMapper mbProductMapper) {
        this.mbProductMapper = mbProductMapper;
    }

    @PostMapping(value = "createProduct")
    public AjaxResp createProduct(@RequestBody BizProduct product) {
        int result = this.mbProductMapper.insert(product);
        return new AjaxResp(result);
    }

    @GetMapping(value = "searchProduct")
    public AjaxResp searchProduct() {
        QueryWrapper<BizProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderBy(true, true, "product_code");
        List<BizProduct> productList = this.mbProductMapper.selectList(queryWrapper);
        return new AjaxResp(productList);
    }
}
